package db

import (
	"database/sql"
	"echo_prj/conf"
	"errors"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

var ulwebsiteDb *sql.DB

func init() {
	var err error
	ulwebsiteDb, err = sql.Open("mysql", conf.Conf.MySqlDb)
	if err != nil {
		panic(err)
	}
	if err = ulwebsiteDb.Ping(); err != nil {
		panic(err.Error())
	}
	ulwebsiteDb.SetConnMaxLifetime(4 * time.Hour)

}

func Login(userName string, passWord string) (id int, err error) {
	err = ulwebsiteDb.QueryRow("SELECT id FROM admin WHERE username = ? And passWord = ?", userName, passWord).Scan(&id)
	if err != nil {
		err = errors.New("账号密码错误")
		return
	}

	return
}
